Registering CommandListeners
As mentioned earlier, an instance of the MIDP List class (theList) implements the Displayable interface. The Displayable interface requires that a CommandListener be registered to it in order to process user input. I set the CommandListener in the constructor of RTTTLEx, as shown in Listing 5.
Listing 5 The Constructor for RTTTLEx
public RTTTLEx() {
instance = this;
display = Display.getDisplay(this);
//Create a new MIDP List
theList = new List("RTTTLEx Ring Tones",
Choice.IMPLICIT);
//Traverse the captions array and add the array's contents
//to the list.
for (int i = 0; i < mcaptions.length; i++) {
theList.append(mcaptions[i], null);
}
//Add Command objects to the List object
theList.addCommand(playCommand);
theList.addCommand(exitCommand);
//Register the List to be the
//CommandListener for the application
theList.setCommandListener(this);
}
8. The Methods of a MIDlet | Next SectionPrevious Section


Make a New Comment
You must login in order to post a comment.